<?php

namespace Biz\model\FineGoodsBrokeNews;

class FineGoodsBrokeNewsFavouriteLogModel extends \Doraemon\pockets\datebase\BaseDbModel
{
    public const _CONFIG_FILE_ = 'db_store';

    public const _CONFIG_SELECT_ = 'db_brand_activity';

    public const _DATABASE_ = 'brand_activity';

    public const _TABLE_NAME = 'fine_goods_broke_news_favourite_log';

    const FAV_CHANGE_STEP = 1;

    /**
     * @param string $datetime
     * @return array|bool
     */
    public static function getLog(string $datetime)
    {
        return self::select(["basic_id", "fav_count"], ['log_time' => $datetime]) ?? [];
    }

    /**
     * @param int $basic_id
     * @param string $datetime
     * @param int $favNum
     * @return bool|\PDOStatement
     */
    public static function addLog(int $basic_id, string $datetime, int $favNum)
    {
        return self::insert([
            'basic_id' => $basic_id,
            'log_time' => $datetime,
            'fav_count' => $favNum,
        ]);
    }

    /**
     * 添加收藏数
     * @param array $basicID
     */
    public static function increaseFavCount(array $basicID)
    {
        self::update(["fav_count[+]" => self::FAV_CHANGE_STEP],['basic_id' => $basicID]);
    }

    /**
     * 减少收藏数
     * @param array $basicID
     */
    public static function decreaseFavCount(array $basicID)
    {
        self::update(["fav_count[-]" => self::FAV_CHANGE_STEP],['basic_id' => $basicID]);
    }
}